/**
 *
 */
package demo.tellurium.module

import groovy.lang.MetaClass;


import demo.tellurium.framework.BaseUIModule;

/**
 * @author roger.xu
 *
 */
class DemoModule extends BaseUIModule {

    @Override
    public void defineUi() {
        ui.Container(uid: "Demo") {
            Div(uid: "TestDiv", clocator: [id: "uiDiv"], respond: ["mouseDown"])
            Container(uid: "OfferingType") {
                Container(uid: "ComboBox", clocator: [widgetid: "offeringType"]) {
                    Div(uid: "ArrowButton", clocator: [class: "dijitArrowButton"], respond: ["mouseDown", "mouseUp", "mouseEnter", "mouseLeave"])
                    Container(uid: "InputField", clocator: [tag: "div", class: "dijitInputField"]) {
                        InputBox(uid: "InputTextBox", clocator: [tag: "input", type: "text"])
                    }
                }
                Container(uid: "ComboBoxPopUp", clocator: [tag: "div", dijitpopupparent: "offeringType"]) {
                    List(uid: "OptionList", clocator: [tag: "ul"], separator: "li:visible") {
                        UrlLink(uid: "{all}", respond: ["mouseDown", "mouseUp", "mouseOver"])
                    }
                }
            }
        }
    }

    public String url = "http://9.186.10.174:8080/CQP4/test.jsp";


    /* ---- Div ---------------*/
    public void doClickDiv() {
        click "Demo.TestDiv"
        pause 500
    }

    public void doMouseDownDiv() {
        mouseDown "Demo.TestDiv"
        pause 500
    }

    public void doSelectItem(int index) {
        click "Demo.OfferingType.ComboBox.ArrowButton"
        pause 1000

        def uid = String.format("Demo.OfferingType.ComboBoxPopUp.OptionList[%d]", index);
        click uid
        pause 1000
    }

    public String getComboBoxValue() {
        def uid = "Demo.OfferingType.ComboBox.InputField.InputTextBox";
        return getValue(uid);
    }

}
